(() => {
    // 使用泛型创建工厂函数是，需要引用钩子函数的类类型
    function createdFn<T>(args: { new(): T }) {
        return new args()
    }

    // 使用原型属性推断并约束构造函数与类实例的关系
    class CatKeeper {
        hasMask: boolean
    }
    class PigKeeper {
        nametag: string
    }
    class Animal {
        numLegs: number
    }

    class Cat extends Animal {
        keeper: CatKeeper
    }
    class Pig extends Animal {
        keeper: PigKeeper
    }

    function create<T extends Animal>(c: new () => T): T {
        return new c
    }

    // 
    create(Cat).numLegs
    create(Cat).keeper.hasMask
    
    create(Pig).numLegs
    create(Pig).keeper.nametag
})()